package com.example.asus.keshe;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

//implements View.OnClickListener 实现这个接口，当前类就是点击事件的监听器
public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private static final String TAG = "MainActivity";


    //定义一个组件EditText对象
    private EditText editText1,editText2;

    //定义一个组件Button对象
    private Button button,button1,button2,button3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //从布局文件文件中取出ID是text1的组件
        /*textView = (TextView)findViewById(R.id.text1);
        //给textView重新赋值
        textView.setText("你好");*/

        //从布局文件文件中取出ID是button2的组件
        button = (Button)findViewById(R.id.button2);
        button1 = (Button)findViewById(R.id.button4);
        button2 = (Button)findViewById(R.id.button3);
        button3=(Button)findViewById(R.id.button_r);
        editText1 = (EditText)findViewById(R.id.editText1);
        editText2 = (EditText)findViewById(R.id.editText2);
        //给按钮添加监听器
        button.setOnClickListener(this);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
    }

    /**
     * 监听点击按钮事件
     * @param v
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()){ //判断点击的按钮的id
            case R.id.button2:
                //取两个文本框的值
                String username = editText1.getText().toString();
                String password = editText2.getText().toString();
                //Intent:意图类
                Intent intent = new Intent();
                //构造一个bundle(用法和HashMap一样)对象，把需要传递的值放入
                Bundle bundle = new Bundle();
                bundle.putString("username",username);
                bundle.putString("password",password);
                //把bundle放入intent
                intent.putExtras(bundle);
                //设置从当前的activity跳转到目标的Activity
                /*intent.setClass(this,FirstActivity.class);
                //跳转
                */
            case R.id.button_r:
                Intent intent3 = new Intent();
                intent3.setClass(this,RegisterActivity.class);
                startActivity(intent3);
                break;
        }

    }
}
